package com.lap.generator.domain.valueobject;

import java.util.stream.Stream;
import lombok.Getter;

@Getter
public enum JavaType {
  INT("Integer"),
  LONG("Long"),
  BIG("BigDecimal"),
  DOU("Double"),
  LOCAL_DATE("LocalDate"),
  LOCAL_DATE_TIME("LocalDateTime"),
  LOCAL_TIME("LocalTime"),
  BOOL("Boolean"),
  STRING("String"),
  ;
  private final String code;

  JavaType(String code) {
    this.code = code;
  }

  public static boolean eqStr(JavaType type) {
    return STRING == type;
  }

  public static boolean eqNumber(JavaType type) {
    return switch (type) {
      case INT, LONG, BIG, DOU -> true;
      default -> false;
    };
  }

  public static boolean isDate(JavaType type) {
    return switch (type) {
      case LOCAL_DATE, LOCAL_DATE_TIME, LOCAL_TIME -> true;
      default -> false;
    };
  }

  public static JavaType createNew(String code) {
    return Stream.of(JavaType.values())
        .filter(item -> item.code.equals(code))
        .findFirst()
        .orElse(null);
  }
}
